package com.hsnn.medstgmini.pro.base.service.Impl;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsnn.medstgmini.pro.base.dao.AnaDruginfoCSDao;
import com.hsnn.medstgmini.pro.base.service.AnaDruginfoCSManager;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.ParseDate;
import com.hsnn.medstgmini.util.ParseNumber;
import com.hsnn.medstgmini.util.DateUtil;

@Service
public class AnaDruginfoCSManagerImpl implements AnaDruginfoCSManager {
	@Autowired
	private AnaDruginfoCSDao anaDruginfoDao;

	@Override
	public Pagination getAnaByDrugs(Pagination page) {
		
		//获取药品采购日汇总信息
		Pagination anaTotal = anaDruginfoDao.getAnaByDrugs(page);
		//获取药品采购总量日汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaChartByDrugs();
		String yDrug = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			Map<String, Object> map = list.get(i);
			yDrug = yDrug +"'"+map.get("drug_name")+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yDrug)) {//判断是否为空
			yDrug = yDrug.substring(0, yDrug.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yDrug", yDrug);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaByHosp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getAnaByHosp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			Object date = data.get("date");
			data.put("date", date==null?"":date.toString().substring(0, 4)+"-"+date.toString().substring(4, 6)+"-"+date.toString().substring(6, 8));
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalYesterday();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = DateUtil.date(new Timestamp(System.currentTimeMillis()-1000 * 60 * 60 * 24)).replaceAll("-", "");
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("hosp_name").toString();
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}		
		page.getConditions().put("chartTitle", date+"医院采购统计");	
		return page;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaByArea(Pagination page) {
		page = anaDruginfoDao.getAnaByArea(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ration", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		//获取地区每日销售量前十的地区信息
		List<Map<String, Object>> chartList = anaDruginfoDao.getAnaChartByArea();
		String yArea = "[";//图表y轴地区名称
		String total = "[";//采购金额
		String base = "[";//基药金额
		String nobase = "[";//非基药金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<chartList.size();i++) {
			Map<String, Object> map = chartList.get(i);
			yArea = yArea +"'"+map.get("area_name")+ "',";
			total = total + map.get("total_amount") + ",";
			base = base + map.get("base_amount") + ",";
			nobase = nobase + map.get("nonbase_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yArea)) {//判断是否为空
			yArea = yArea.substring(0, yArea.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			base = base.substring(0, base.length()-1) + "]";
			nobase = nobase.substring(0, nobase.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yArea", yArea);
			page.getConditions().put("total", total);
			page.getConditions().put("base", base);
			page.getConditions().put("nobase", nobase);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}
		return page;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaCompinfoByArea(Pagination page) {
		page = anaDruginfoDao.getAnaCompinfoByArea(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ratio", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		return page;
	}
	/**
	 * 
	 *@category 获取药品采购统计,跳向按地区查询数据（年）
	 *@author 邱磊
	 *@date 2015年12月3日 上午10:06:50
	 *@param 
	 *@return Pagination
	 */
	@SuppressWarnings("unchecked")
	public Pagination getAnaByAreaWithYear(Pagination page){
		page =  anaDruginfoDao.getAnaByAreaWithYear(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ration", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		//获取地区销售量前十的上一年地区信息
		List<Map<String, Object>> chartList = anaDruginfoDao.getAnaChartByAreaWithYear();
		String yArea = "[";//图表y轴地区名称
		String total = "[";//采购金额
		String base = "[";//基药金额
		String nobase = "[";//非基药金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<chartList.size();i++) {
			Map<String, Object> map = chartList.get(i);
			yArea = yArea +"'"+map.get("area_name")+ "',";
			total = total + map.get("total_amount") + ",";
			base = base + map.get("base_amount") + ",";
			nobase = nobase + map.get("nonbase_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yArea)) {//判断是否为空
			yArea = yArea.substring(0, yArea.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			base = base.substring(0, base.length()-1) + "]";
			nobase = nobase.substring(0, nobase.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yArea", yArea);
			page.getConditions().put("total", total);
			page.getConditions().put("base", base);
			page.getConditions().put("nobase", nobase);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}
		return page;
	}
	
	@SuppressWarnings("unchecked")
	public Pagination getAnaCompinfoByAreaWithYear(Pagination page){
		page =  anaDruginfoDao.getAnaCompinfoByAreaWithYear(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ration", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		return page;
	}

	/**
	 * 
	 *@category 获取药品采购统计,跳向按地区查询数据（季）
	 *@author 邱磊
	 *@date 2015年12月3日 上午10:06:50
	 *@param 
	 *@return Pagination
	 */
	@SuppressWarnings("unchecked")
	public Pagination getAnaByAreaWithSea(Pagination page){
		page =  anaDruginfoDao.getAnaByAreaWithSea(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ration", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		//获取地区销售量前十的上一季度地区信息
		List<Map<String, Object>> chartList = anaDruginfoDao.getAnaChartByAreaWithSea();
		String yArea = "[";//图表y轴地区名称
		String total = "[";//采购金额
		String base = "[";//基药金额
		String nobase = "[";//非基药金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<chartList.size();i++) {
			Map<String, Object> map = chartList.get(i);
			yArea = yArea +"'"+map.get("area_name")+ "',";
			total = total + map.get("total_amount") + ",";
			base = base + map.get("base_amount") + ",";
			nobase = nobase + map.get("nonbase_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yArea)) {//判断是否为空
			yArea = yArea.substring(0, yArea.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			base = base.substring(0, base.length()-1) + "]";
			nobase = nobase.substring(0, nobase.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yArea", yArea);
			page.getConditions().put("total", total);
			page.getConditions().put("base", base);
			page.getConditions().put("nobase", nobase);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}
		return page;
	}
	
	@SuppressWarnings("unchecked")
	public Pagination getAnaCompinfoByAreaWithSea(Pagination page){
		page =  anaDruginfoDao.getAnaCompinfoByAreaWithSea(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ration", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		return page;
	}
	/**
	 * @category 按医院统计(年)
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getYearAnaByHosp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getYearAnaByHosp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalLastYear();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = (Calendar.getInstance().get(Calendar.YEAR)-1)+"";
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("hosp_name").toString();
			date = map.get("date")+"";
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}
		page.getConditions().put("chartTitle", date+"医院采购统计");
		return page;
				
	}
	
	@SuppressWarnings("unchecked")
	public Pagination getAnaByAreaWithMon(Pagination page){
		page =  anaDruginfoDao.getAnaByAreaWithMon(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ration", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		//获取地区销售量前十的上一月地区信息
		List<Map<String, Object>> chartList = anaDruginfoDao.getAnaChartByAreaWithMon();
		String yArea = "[";//图表y轴地区名称
		String total = "[";//采购金额
		String base = "[";//基药金额
		String nobase = "[";//非基药金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<chartList.size();i++) {
			Map<String, Object> map = chartList.get(i);
			yArea = yArea +"'"+map.get("area_name")+ "',";
			total = total + map.get("total_amount") + ",";
			base = base + map.get("base_amount") + ",";
			nobase = nobase + map.get("nonbase_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yArea)) {//判断是否为空
			yArea = yArea.substring(0, yArea.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			base = base.substring(0, base.length()-1) + "]";
			nobase = nobase.substring(0, nobase.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yArea", yArea);
			page.getConditions().put("total", total);
			page.getConditions().put("base", base);
			page.getConditions().put("nobase", nobase);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}
		return page;
	}
	@SuppressWarnings("unchecked")
	public Pagination getAnaCompinfoByAreaWithMon(Pagination page){
		page =  anaDruginfoDao.getAnaCompinfoByAreaWithMon(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("base_amount", map.get("base_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_amount").toString()), 3));
				map.put("nonbase_amount", map.get("nonbase_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("nonbase_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("base_ratio", map.get("base_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("base_ratio").toString()) * 100, 6) + "%");
				map.put("del_ration", map.get("del_ration")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ration").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		return page;
	}
	/**
	 * @category 按医院统计(季度)
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getSeaAnaByHosp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getSeaAnaByHosp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			Object date = data.get("date");
			data.put("date", date==null?"":date.toString().substring(0, 4)+"年"+date.toString().substring(4, 6)+"季度");
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalLastQuarter();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = ParseDate.getSea(ParseDate.addMonth(new Date(), -3));
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("hosp_name").toString();
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}	
		page.getConditions().put("chartTitle", date+"季度医院采购统计");
		return page;
	}
	
	/**
	 * @category 按医院统计(月)
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getMonthAnaByHosp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getMonthAnaByHosp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			Object date = data.get("date");
			data.put("date", date==null?"":date.toString().substring(0, 4)+"-"+date.toString().substring(4, 6));
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalLastMonth();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = ParseDate.parseDateToYm(ParseDate.addMonth(new Date(), -1));
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("hosp_name").toString();
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}	
		page.getConditions().put("chartTitle", date+"医院采购统计");	
		return page;
	}
	
	/**
	 * @category 按药品汇总（月）
	 * @date 2015-12-04
	 * @author lil
	 * @param page
	 * @return Pagination
	 */
	@Override
	public Pagination getAnaByDrugsMonth(Pagination page) {
		
		//获取药品采购月汇总信息
		Pagination anaTotal = anaDruginfoDao.getAnaByDrugsMonth(page);
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaChartByDrugsMon();
		String yDrug = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			Map<String, Object> map = list.get(i);
			yDrug = yDrug +"'"+map.get("drug_name")+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yDrug)) {//判断是否为空
			yDrug = yDrug.substring(0, yDrug.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yDrug", yDrug);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}
	
	/**
	 * @category 按药品汇总（季度）
	 * @date 2015-12-04
	 * @author lil
	 * @param page
	 * @return Pagination
	 */
	@Override
	public Pagination getAnaByDrugsSea(Pagination page) {
		
		//获取药品采购季度汇总信息
		Pagination anaTotal = anaDruginfoDao.getAnaByDrugsSea(page);
		//获取药品采购总量季度汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaChartByDrugsSea();
		String yDrug = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			Map<String, Object> map = list.get(i);
			yDrug = yDrug +"'"+map.get("drug_name")+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yDrug)) {//判断是否为空
			yDrug = yDrug.substring(0, yDrug.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yDrug", yDrug);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}
	
	/**
	 * @category 按药品汇总（年度）
	 * @date 2015-12-04
	 * @author lil
	 * @param page
	 * @return Pagination
	 */
	@Override
	public Pagination getAnaByDrugsYear(Pagination page) {
		
		//获取药品采购年汇总信息
		Pagination anaTotal = anaDruginfoDao.getAnaByDrugsYear(page);
		//获取药品采购总量年汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaChartByDrugsYear();
		String yDrug = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			Map<String, Object> map = list.get(i);
			yDrug = yDrug +"'"+map.get("drug_name")+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yDrug)) {//判断是否为空
			yDrug = yDrug.substring(0, yDrug.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yDrug", yDrug);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}
	
	/**
	 * @category 获取药品采购总量日汇总数据
	 * @date 2015年12月03日
	 * @author lil
	 * @param page
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaListByTime(Pagination page) {
		
		//获取药品采购总量日汇总数据
		Pagination anaTotal = anaDruginfoDao.getAnaListByTime(page);
		List<Map<String, Object>> listPage = (List<Map<String, Object>>) page.getRows();
		if (null != listPage && listPage.size() > 0){
			for (int i = 0; i < listPage.size(); i++){
				Map<String, Object> map = listPage.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("del_ratio", map.get("del_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ratio").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		
		//获取药品采购总量日汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaTotalByTime();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			
			Map<String, Object> map = list.get(i);
			String isBasic =  Integer.parseInt(map.get("is_basic")+"") == 1?"基药":"非基药";
			String date = map.get("date")+"";
			yTime = yTime +"'"+date+isBasic+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yTime", yTime);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}
	
	/**
	 * @category 获取药品采购总量月汇总数据
	 * @date 2015年12月03日
	 * @author lil
	 * @param page
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaListByTimeMonthCS(Pagination page) {
		
		//获取药品采购总量月汇总数据
		Pagination anaTotal = anaDruginfoDao.getAnaListByTimeMonthCS(page);
		List<Map<String, Object>> listPage = (List<Map<String, Object>>) page.getRows();
		if (null != listPage && listPage.size() > 0){
			for (int i = 0; i < listPage.size(); i++){
				Map<String, Object> map = listPage.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("del_ratio", map.get("del_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ratio").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaTotalByTimeMonth();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			Map<String, Object> map = list.get(i);
			String isBasic =  Integer.parseInt(map.get("is_basic")+"") == 1?"基药":"非基药";
			String date = map.get("date")+"";
			yTime = yTime +"'"+date+isBasic+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yTime", yTime);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}
	
	/**
	 * @category 获取药品采购总量季度汇总数据
	 * @date 2015年12月03日
	 * @author lil
	 * @param page
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaListByTimeQuarterCS(Pagination page) {
		
		//获取药品采购总量季度汇总数据
		Pagination anaTotal = anaDruginfoDao.getAnaListByTimeQuarterCS(page);
		List<Map<String, Object>> listPage = (List<Map<String, Object>>) page.getRows();
		if (null != listPage && listPage.size() > 0){
			for (int i = 0; i < listPage.size(); i++){
				Map<String, Object> map = listPage.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("del_ratio", map.get("del_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ratio").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		//获取药品采购总量季度汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaTotalByTimeQuarter();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			Map<String, Object> map = list.get(i);
			String isBasic =  Integer.parseInt(map.get("is_basic")+"") == 1?"基药":"非基药";
			String date = map.get("date")+"";
			yTime = yTime +"'"+date+isBasic+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yTime", yTime);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}
	
	/**
	 * @category 获取药品采购总量年汇总数据
	 * @date 2015年12月03日
	 * @author lil
	 * @param page
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaListByTimeYearCS(Pagination page) {
		
		//获取药品采购总量年汇总数据
		Pagination anaTotal = anaDruginfoDao.getAnaListByTimeYearCS(page);
		List<Map<String, Object>> listPage = (List<Map<String, Object>>) page.getRows();
		if (null != listPage && listPage.size() > 0){
			for (int i = 0; i < listPage.size(); i++){
				Map<String, Object> map = listPage.get(i);
				map.put("total_amount", map.get("total_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("total_amount").toString()), 3));
				map.put("del_amount", map.get("del_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_amount").toString()), 3));
				map.put("ret_amount", map.get("ret_amount")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_amount").toString()), 3));
				map.put("del_ratio", map.get("del_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("del_ratio").toString()) * 100, 6) + "%");
				map.put("ret_ratio", map.get("ret_ratio")==null?"":ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("ret_ratio").toString()) * 100, 6) + "%");
			}
		}
		
		
		//获取药品采购总量年汇总集合
		List<Map<String, Object>> list = anaDruginfoDao.getAnaTotalByTimeYear();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<list.size();i++) {
			Map<String, Object> map = list.get(i);
			String isBasic =  Integer.parseInt(map.get("is_basic")+"") == 1?"基药":"非基药";
			String date = map.get("date")+"";
			yTime = yTime +"'"+date+isBasic+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			anaTotal.getConditions().put("yTime", yTime);
			anaTotal.getConditions().put("total", total);
			anaTotal.getConditions().put("del", del);
			anaTotal.getConditions().put("ret", ret);
		}
		
		return anaTotal;
	}
	
	/**
	 * @category 按企业统计(日)
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getAnaByComp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getAnaByComp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			Object date = data.get("date");
			data.put("date", date==null?"":date.toString().substring(0, 4)+"-"+date.toString().substring(4, 6)+"-"+date.toString().substring(6, 8));
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalByCompYesterday();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = DateUtil.date(new Timestamp(System.currentTimeMillis()-1000 * 60 * 60 * 24)).replaceAll("-", "");
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("del_comp_name").toString();
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}		
		page.getConditions().put("chartTitle", date+"企业采购统计");	
		return page;
	}
	
	/**
	 * @category 按企业统计(年)
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getYearAnaByComp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getYearAnaByComp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalByCompLastYear();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = (Calendar.getInstance().get(Calendar.YEAR)-1)+"";
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("del_comp_name").toString();
			date = map.get("date")+"";
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}
		page.getConditions().put("chartTitle", date+"企业采购统计");
		return page;
				
	}
	
	/**
	 * @category 按企业统计(季度)
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getSeaAnaByComp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getSeaAnaByComp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			Object date = data.get("date");
			data.put("date", date==null?"":date.toString().substring(0, 4)+"年"+date.toString().substring(4, 6)+"季度");
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalByCompLastQuarter();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = ParseDate.getSea(ParseDate.addMonth(new Date(), -3));
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("del_comp_name").toString();
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}	
		page.getConditions().put("chartTitle", date+"季度企业采购统计");
		return page;
	}
	
	/**
	 * @category 按企业统计(月)
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getMonthAnaByComp(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) anaDruginfoDao.getMonthAnaByComp(page).getRows();
		for(Map<String,Object> data : list){
			Object base_ratio = data.get("base_ratio");
			Object ret_ratio = data.get("ret_ratio");
			Object date = data.get("date");
			data.put("date", date==null?"":date.toString().substring(0, 4)+"-"+date.toString().substring(4, 6));
			data.put("base_ratio", base_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(base_ratio.toString())*100,6)+"%");
			data.put("ret_ratio", ret_ratio==null?"":ParseNumber.toStrDecimal(Double.parseDouble(ret_ratio.toString())*100,6)+"%");
		}
		
		//获取药品采购总量月汇总集合
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getAnaTotalByCompLastMonth();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		String date = ParseDate.parseDateToYm(ParseDate.addMonth(new Date(), -1));
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String hospName =  map.get("del_comp_name").toString();
			yTime = yTime +"'"+hospName+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}	
		page.getConditions().put("chartTitle", date+"企业采购统计");	
		return page;
	}
	
	/**
	 * @category 首页的柱状图数据
	 * @date 2015年12月1日10:55:55
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getHomeChartData(Pagination page) {
		List<Map<String, Object>> totalList = (List<Map<String, Object>>) anaDruginfoDao.getHomeChartData();
		String yTime = "[";//图表y轴时间
		String total = "[";//采购金额
		String del = "[";//配送金额
		String ret = "[";//退货金额
		//循环解析数据
		for(int i =0;i<totalList.size();i++) {
			Map<String, Object> map = totalList.get(i);
			String isBasic = map.get("is_basic")==null?"":"1".equals(map.get("is_basic").toString())?"基药":"非基药 ";
			String date =  map.get("date").toString();
			yTime = yTime +"'"+date+isBasic+ "',";
			total = total + map.get("total_amount") + ",";
			del = del + map.get("del_amount") + ",";
			ret = ret + map.get("ret_amount") + ",";
		}
		
		if(!"[".equals(yTime)) {//判断是否为空
			yTime = yTime.substring(0, yTime.length()-1) + "]";
			total = total.substring(0, total.length()-1) + "]";
			del = del.substring(0, del.length()-1) + "]";
			ret = ret.substring(0, ret.length()-1) + "]";
			
			page.getConditions().put("yTime", yTime);
			page.getConditions().put("total", total);
			page.getConditions().put("del", del);
			page.getConditions().put("ret", ret);
		}	
		return page;
	}
}
